import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDHandBook {
	/**编号*/
	id,
	/**图鉴类型--1.装备--2.宠物--3.怪物*/
	handbook,
	/**名称*/
	name,
	/**标题*/
	title,
	/**分组*/
	group,
	/**图鉴道具类型--1-5item表格道具1.资源点2.道具3.装备4.符文5.魔纹--6.宠物7.怪物*/
	itemType,
	/**图鉴道具id*/
	itemid,
	/**激活道具奖励*/
	reward,

	/**枚举数量*/
	EnumCount
}



export class CDHandBook{
	/**编号*/
	public id: number;
	/**图鉴类型--1.装备--2.宠物--3.怪物*/
	public handbook: number;
	/**名称*/
	public name: number;
	/**标题*/
	public title: number;
	/**分组*/
	public group: number;
	/**图鉴道具类型--1-5item表格道具1.资源点2.道具3.装备4.符文5.魔纹--6.宠物7.怪物*/
	public itemType: number;
	/**图鉴道具id*/
	public itemid: number;
	/**激活道具奖励*/
	public reward: number;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDHandBook.id: return this.id;
			case E_CDHandBook.handbook: return this.handbook;
			case E_CDHandBook.name: return this.name;
			case E_CDHandBook.title: return this.title;
			case E_CDHandBook.group: return this.group;
			case E_CDHandBook.itemType: return this.itemType;
			case E_CDHandBook.itemid: return this.itemid;
			case E_CDHandBook.reward: return this.reward;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDHandBook.id: this.id = v; break;
			case E_CDHandBook.handbook: this.handbook = v; break;
			case E_CDHandBook.name: this.name = v; break;
			case E_CDHandBook.title: this.title = v; break;
			case E_CDHandBook.group: this.group = v; break;
			case E_CDHandBook.itemType: this.itemType = v; break;
			case E_CDHandBook.itemid: this.itemid = v; break;
			case E_CDHandBook.reward: this.reward = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDHandBook> = new HashMap<number, CDHandBook>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDHandBook[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDHandBook();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].handbook = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].name = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].title = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].group = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].itemType = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].itemid = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].reward = byte.readInt32();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDHandBook{
		return this.datas ? this.datas.get(id) : null;
	}
}
